import { Component } from '@angular/core';
import { NavController,NavParams,AlertController } from 'ionic-angular';
import { HomePage } from '../home/home';
import { HttpService } from '../../providers/http.service';
import { CommonFunc } from '../../providers/commonFunc';
/**
 * 维修历史
 */
@Component({
  templateUrl: 'repair-history.html'
})
export class RepairHistory {
  private list : any;
  private elevatorId;
  private pageSize:number=10;
  private currentPage:number=1;
  private currentUserId:any;
  constructor(
    public navCtrl: NavController,
    private alertCtrl: AlertController,
    private httpService: HttpService,
    private navParams: NavParams,
    private commonFunc: CommonFunc
  ) {
    this.elevatorId = this.navParams.get('elevatorId');

    let observable2 = this.httpService.queryRepairList({elevatorId: this.elevatorId,pageSize:this.pageSize, currentPage: this.currentPage});
     
    observable2.subscribe( data => {
      if(data.status==200){
        this.list = data.data.list;
      }

    });
   
  }

  //刷新
doRefresh(refresher) {
  setTimeout(()=>{
      this.currentPage++;
      let params:any={};
      params.pageSize=this.pageSize+"";
      params.currentPage=this.currentPage+"";
      params.elevatorId = this.elevatorId;
      
      let ob = this.httpService.queryRepairList({elevatorId: this.elevatorId,pageSize:this.pageSize, currentPage: this.currentPage});
     
      ob.subscribe(data=>{
          if (data.status !=200) {
              let toast = this.commonFunc.showInsideErrorToast(data.message);
              toast.present();
              return;
          }
          if(data.data.list.length<=0){
              refresher.enabled = false;
              // setTimeout(()=> {
              //     refresher.enabled = true;
              // },3000);
          }else{
              data.data.list.forEach(e=>{
                  this.list.unshift(e);
              });
          }
      });

      refresher.complete();
  },2000);

}
  


}
